﻿using Main.DataBaseContext;
using Main.ViewModels;
using Main.Views;
using Prism.DryIoc;
using Prism.Ioc;
using System.Windows;

namespace Main
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App:PrismApplication
    {

        public const string AddToDoTaskDialogName = "AddToDoTaskDialog";

        public const string AddMemoDialogName = "AddMemoDialog";
        public const string IndexViewName = "IndexView";
        public const string ToDoTaskViewName = "ToDoTaskView";

        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<BusnessContext>( () => {

                BusnessContext busnessContext = new BusnessContext();

                /* 创建的时候先移除所有表格
                 https://learn.microsoft.com/en-us/ef/core/managing-schemas/ensure-created
                 */
                //busnessContext.Database.EnsureDeleted();
                busnessContext.Database.EnsureCreated();

                return busnessContext;
            });

            containerRegistry.RegisterDialog<AddToDoTaskDialog, AddToDoTaskDialogViewModel>(AddToDoTaskDialogName);

            containerRegistry.RegisterDialog<AddMemoDialog, AddMemoDialogViewModel>(AddMemoDialogName);

            containerRegistry.RegisterForNavigation<IndexView, IndexViewModel>(IndexViewName);

            containerRegistry.RegisterForNavigation<ToDoTaskView, ToDoTaskViewModel>(ToDoTaskViewName);
        }
    }
}
